<?php 
$this->breadcrumbs=array(
	'Карта сайта',
);
?>

<h1>Карта сайта</h1>
<div class="grid-view">
	<div class="sitemap-content sitemap-content-ajax">
		<ul class="sitemap-level-1">
			<li>
				<a href="<?php echo Yii::app()->createUrl('site/sitemap'); ?>"><?php echo CHtml::encode(Yii::app()->params['sitename']); ?></a>
				<ul class="sitemap-level-2">
					<?php if(!empty($content)) : ?>
						<li>
							<span class="btn <?php echo 'plus'; ?>"></span><span class="icon icon-folder"></span><a href="<?php echo Yii::app()->createUrl(''); ?>">Материалы</a>
							<?php Categories($content); ?>
						</li>
					<?php endif ?>
					<?php if(!empty($gallery)) : ?>
						<li>
							<span class="btn <?php echo 'plus'; ?>"></span><span class="icon icon-folder"></span><a href="<?php echo Yii::app()->createUrl(''); ?>">Галерея</a>
							<?php Categories($gallery); ?>
						</li>
					<?php endif ?>
					
					<?php if(!empty($videos)) : ?>
						<li>
							<span class="btn <?php echo 'plus'; ?>"></span><span class="icon icon-folder"></span><a href="<?php echo Yii::app()->createUrl(''); ?>">Видеозаписи</a>
							<?php Categories($videos); ?>
						</li>
					<?php endif ?>
				</ul>
			</li>
		</ul>
	</div>
</div>

<pre>
	<?php 
		function Categories($categories)
		{
			$masCategories = array();
			foreach ($categories as $key => $value) {
				$masCategories[$value->parent_id][$value->id] = $value;
			}
			Category(0, $masCategories);
		}
		function Category($_parent, $categories)
		{
			if(!empty($categories[$_parent]))
			{
				echo '<ul class="child_category">';
				foreach ($categories[$_parent] as $key => $category) : ?>
					<li>
						<span class="btn <?php echo (empty($category->items) && empty($categories[$category->id])) ? 'minus-disable' : 'plus'; ?>"></span><span class="icon icon-folder"></span><a href="<?php echo Yii::app()->createUrl('e/url', array('url_id'=>$category->url_id)); ?>"><?php echo $category->name; ?></a>
						<?php Category($key, $categories); ?>
						<?php if($category->items) : ?>
							<ul class="child_category sitemap-level-3">
								<?php foreach ($category->items as $key_items => $item) : ?>
									<li><span class="btn minus-disable"></span><span class="icon icon-file"></span><a href="<?php echo Yii::app()->createUrl('e/url', array('url_id'=>$item->url_id)); ?>"><?php echo CHtml::encode($item->name); ?></a></li>
								<?php endforeach ?>
							</ul>
						<?php endif ?>
					</li>
				<?php endforeach ?>
				<?php echo '</ul>';
			}
		}
	?>
</pre>